
*******************************************************************************
**
*Table B.2: Effects on value received using alternative specifications
*This table reports alternative specifications for Panel B in Table A.4 by reporting models with March data only, pooled data with a linear trend, and pooled data without baseline lag
*******************************************************************************



use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear

*******************************************************************************
* Keep if surveyed or classified as ghost
keep if ss_code == "SS01" | ghost_final == 1

*******************************************************************************
svyset [pw = pweight]


count if ghost_final == 1
scalar ghosts = r(N)
scalar obs = 3960   

*Get relative weights of AAY and PH rationcard holders by whether RC is in an urban area
sum pweight if rationcardtype == "AAY" & isurban == 0
scalar AAY_weight0 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 0
scalar PH_weight0 = r(sum)

sum pweight if rationcardtype == "AAY" & isurban == 1
scalar AAY_weight1 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 1
scalar PH_weight1 = r(sum)


*******************************************
* March only
*******************************************

local tflist ""
local tflist_noBL ""

*Quantity purchased of each ration commodity
loc ration "rice wheat sugar salt kero"

foreach rat of local ration {

gen bl_var = `rat'_weigh_y0
egen bl_var_mean = mean(`rat'_weigh_y0)
gen bl_var_mi = missing(`rat'_weigh_y0)
replace bl_var = bl_var_mean if bl_var_mi == 1

*Control mean of outcome
qui svy: mean b16_`rat'_weigh_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)


*Statutory NIC entitlement
qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)


*March only estimates
eststo mar_`rat': xi: reg b16_`rat'_weigh_mar17  treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)
estadd scalar percent_obs 100*e(N)/obs

tempfile mar_`rat'
parmest, label saving("`mar_`rat''")
local tflist_noBL "`tflist_noBL' `mar_`rat''"

eststo mar_`rat'BL: xi: reg b16_`rat'_weigh_mar17 treatment bl_var bl_var_mi i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)
estadd scalar percent_obs 100*e(N)/obs

tempfile mar_`rat'BL
parmest, label saving("`mar_`rat'BL'")
local tflist "`tflist' `mar_`rat'BL'"


drop bl_var*
}



*Output table
preserve

dsconcat `tflist',subset(parm p in 1) dsn(ds_ration)   
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local estname: word `i' of `tflist'
local rat: word `i' of `ration'

estimates restore mar_`rat'BL

mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue) 
}

loc tabname "${OutputDir}/TableB_2.tex" 
cd "${adoDir}"
loc nc 5				
				
MultiPartTabStart, ///
			ncol(`nc') tabname(`tabname') ///
			colnames("Rice" "Wheat" "Sugar" "Salt" "Kerosene") width("\hsize")			
				
				
MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel A: March only")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("*riceBL *wheatBL *sugarBL *saltBL *keroBL") ///
				drop(_cons _Istrata* bl_var*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment" , elist(treatment \addlinespace)  )  ///
				stats(control_mean N,  ///
					labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))
restore	

preserve

dsconcat `tflist_noBL', subset(parm p in 1) dsn(ds_ration)  
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local estname: word `i' of `tflist_noBL'
local rat: word `i' of `ration'

estimates restore mar_`rat'


mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue) 
}


restore

*******************************************
* Pooled
*******************************************

local tflist ""
local tflist_noBL ""
local tflist_trend ""
local tflist_trend_noBL ""
foreach rat of local ration {


gen bl_var = `rat'_weigh_y0
egen bl_var_mean = mean(`rat'_weigh_y0)
gen bl_var_mi = missing(`rat'_weigh_y0)
replace bl_var = bl_var_mean if bl_var_mi == 1



preserve
keep uid b16_`rat'_weigh_jan17 b16_`rat'_weigh_feb17 b16_`rat'_weigh_mar17 ent_quantity_`rat'_* stat_ent_quantity_`rat' bl_var bl_var_mi treatment strata pweight block_code rationcardtype isurban
gen b16_`rat'_weigh3 = b16_`rat'_weigh_mar17
gen b16_`rat'_weigh2 = b16_`rat'_weigh_feb17
gen b16_`rat'_weigh1 = b16_`rat'_weigh_jan17
gen ent_quantity_`rat'3 = ent_quantity_`rat'_mar17
gen ent_quantity_`rat'2 = ent_quantity_`rat'_feb17
gen ent_quantity_`rat'1 = ent_quantity_`rat'_jan17
drop b16_`rat'_weigh_mar17 b16_`rat'_weigh_feb17 b16_`rat'_weigh_jan17 ent_quantity_`rat'_mar17 ent_quantity_`rat'_feb17 ent_quantity_`rat'_jan17
reshape long b16_`rat'_weigh ent_quantity_`rat', i(uid) j(month)

count
scalar obs_all = 3*3960

gen treatmentXmonth=treatment*month


qui svy: mean b16_`rat'_weigh if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

* Food department monthly entitlement
qui svy: mean ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0 = r(mean)

qui svy: mean ent_quantity_`rat' if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0 = r(mean)

qui svy: mean ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1 = r(mean)

qui svy: mean ent_quantity_`rat' if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1 = r(mean)

*Statutory NIC entitlement
qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_quantity_`rat' if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)




eststo `rat'pool1: xi: reg b16_`rat'_weigh treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all
estadd scalar ent_mean = (AAY_weight0*`=MeanAAY0[1,1]' + PH_weight0*`=MeanPH0[1,1]' + AAY_weight1*`=MeanAAY1[1,1]' + PH_weight1*`=MeanPH1[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)


tempfile `rat'pool1
parmest, label saving("``rat'pool1'")
local tflist_noBL "`tflist_noBL' ``rat'pool1'"


eststo `rat'pool2: xi: reg b16_`rat'_weigh treatment i.strata month treatmentXmonth  [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all
estadd scalar ent_mean = (AAY_weight0*`=MeanAAY0[1,1]' + PH_weight0*`=MeanPH0[1,1]' + AAY_weight1*`=MeanAAY1[1,1]' + PH_weight1*`=MeanPH1[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)
estadd scalar stat_ent_mean = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)

tempfile `rat'pool2
parmest, label saving("``rat'pool2'")
local tflist_trend_noBL "`tflist_trend_noBL' ``rat'pool2'"

eststo `rat'poolBL1: xi: reg b16_`rat'_weigh treatment bl_var bl_var_mi i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all
estadd scalar ent_mean = (AAY_weight0*`=MeanAAY0[1,1]' + PH_weight0*`=MeanPH0[1,1]' + AAY_weight1*`=MeanAAY1[1,1]' + PH_weight1*`=MeanPH1[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)
estadd scalar stat_ent_mean = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)

tempfile `rat'poolBL1
parmest, label saving("``rat'poolBL1'")
local tflist "`tflist' ``rat'poolBL1'"

eststo `rat'poolBL2: xi: reg b16_`rat'_weigh treatment bl_var bl_var_mi i.strata month treatmentXmonth  [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs_all


estadd scalar ent_mean = (AAY_weight0*`=MeanAAY0[1,1]' + PH_weight0*`=MeanPH0[1,1]' + AAY_weight1*`=MeanAAY1[1,1]' + PH_weight1*`=MeanPH1[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)
estadd scalar stat_ent_mean = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)

tempfile `rat'poolBL2
parmest, label saving("``rat'poolBL2'")
local tflist_trend "`tflist_trend' ``rat'poolBL2'"

restore

drop bl_var*

}




* Output tables

preserve

dsconcat `tflist', subset(parm p in 1) dsn(ds_ration)  
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'poolBL1

mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue) 
}


restore	


preserve

dsconcat `tflist_noBL', subset(parm p in 1) dsn(ds_ration)  
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'pool1


mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue) 
}

restore 

preserve

dsconcat `tflist_trend', subset(parm p in 1) dsn(ds_ration)  
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'poolBL2


mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue) 
}
restore 


MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel B: Pooled data with linear trend")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("ricepoolBL2 wheatpoolBL2 sugarpoolBL2 saltpoolBL2 keropoolBL2") ///
				drop(_cons _Istrata* bl_var*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment"  month "Month" treatmentXmonth "Treatment X Month" , ///
				elist(treatment \addlinespace  month \addlinespace treatmentXmonth \addlinespace)  ) ///
				stats(control_mean N, labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))

MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel C: Pooled data with no baseline lag")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("ricepool1 wheatpool1 sugarpool1 saltpool1 keropool1") ///
				drop(_cons _Istrata*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment" elist(treatment \addlinespace )  ) ///
				stats(control_mean N, labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))

MultiPartTabEnd, ///
				ncol(`nc') tabname(`tabname')

